package com.smartstate.autoMaticControl.websocket;


import com.smartstate.autoMaticControl.config.BeanContext;
import com.smartstate.autoMaticControl.config.SpringUtil;
import com.smartstate.autoMaticControl.entity.Dedusting;
import com.smartstate.autoMaticControl.entity.WebSocketOnMessage;
import com.smartstate.autoMaticControl.service.DeviceDisService;
import com.smartstate.common.web.exception.CommonException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import javax.websocket.Session;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

@Slf4j
public class DataRealTimeRunnable implements Runnable{

    private DeviceDisService deviceDisService;

    private Session session;

    private WebSocketOnMessage webSocketOnMessage;

    public void setSession(Session session,WebSocketOnMessage webSocketOnMessage) {
        deviceDisService = BeanContext.getApplicationContext().getBean(DeviceDisService.class);
        this.session = session;
        this.webSocketOnMessage = webSocketOnMessage;
    }


    @Override
    public void run() {
        long l = System.currentTimeMillis();
        if (!webSocketOnMessage.getDeviceName().isEmpty()){
            try {
               switch (webSocketOnMessage.getDeviceName()){
                   case "Dedusting:*":
                       WebSocketServer.sendInfo(deviceDisService.getArefaction(webSocketOnMessage.getDeviceName()),session);
                       break;
                   default:
                       WebSocketServer.sendInfo("",session);
               }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        long l1 = System.currentTimeMillis();
        System.out.println("l1-l=" + (l1-l));
    }
}

